package cn.iocoder.yudao.module.erp.taskListener;

import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEvent;
import cn.iocoder.yudao.module.bpm.api.event.BpmProcessInstanceStatusEventListener;
import cn.iocoder.yudao.module.erp.service.purchase.ErpPurchaseApplyOrderService;
import cn.iocoder.yudao.module.erp.service.purchase.ErpPurchaseOrderService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 采购申请订单监听器实现类
 *
 * @author 芋道源码
 */
@Component
@Slf4j
public class PurchaseApplyOrderStatusListener extends BpmProcessInstanceStatusEventListener {

    @Resource
    private ErpPurchaseApplyOrderService erpPurchaseOrderService;

    @Value("${task.purchase_applyOrder.key:purchase_applyOrder_audit}")
    private String purchaseOrderTask;

    @Override
    protected String getProcessDefinitionKey() {
        return purchaseOrderTask;
    }

    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        log.info("采购申请订单监听器实现类收到事件：{}", JSON.toJSONString(event));
        Integer status = event.getStatus();
        erpPurchaseOrderService.updateStatus(Long.parseLong(event.getBusinessKey()), status);
//        if(BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(status)){
//            erpPurchaseOrderService.updateStatus(Long.parseLong(event.getBusinessKey()), status);
//        }else if(BpmProcessInstanceStatusEnum.REJECT.getStatus().equals(status)|| BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(status)){
//            erpPurchaseOrderService.updateStatus(Long.parseLong(event.getBusinessKey()), status);
//        }

    }

}
